xcsv TIMET_TIME, TIMET_TIME_MS fix for the last fix. (#490)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Tue, 4 Feb 2020 13:07:36 +0000 (06:07 -0700)
committerGitHub <noreply@github.com>
Tue, 4 Feb 2020 13:07:36 +0000 (06:07 -0700)
* xcsv TIMET_TIME, TIMET_TIME_MS fix for the last fix.

e483407cf recently made a "fix" to TIMET_TIME_MS output.  Unfortunately
it used a non-standard strftime specifier.  While this worked on
linux systems it crashed with MSVC.

This removes strftime processing from TIMET_TIME_MS output.  This makes
TIME_TIME, TIMET_TIME_MS analogous.  Also input and output are
invertbile.  Note that the documentation for these fields never mentioned
strptime or strftime, but says the are long intergers requiring long
integer printf conversions.

* Fix TIMET_TIME, TIMET_TIME_MS documentation.

These have been converted to 64 bit values to prepare for 2038.

* update style files for 64bit TIMET_TIME, TIMET_TIME_MS.

internal_styles.cc
style/custom.style
style/garmin301.style
style/motoactv.style
style/tabsep.style
xcsv.cc
xmldoc/chapters/styles.xml

index 78f92292826d306e6dc931f1f440d507d1bcd98a..d89785ffb854930533f5aa2ebda0b171da51c12a 100644 (file)
@@ -174,7 +174,7 @@ static char custom[] =
   "IFIELD      LON_DIRDECIMAL, \"\", \"%c/%f\"\n"
   "IFIELD      LAT_INT32DEG, \"\", \"%ld\"\n"
   "IFIELD      LON_INT32DEG, \"\", \"%ld\"\n"
-  "IFIELD      TIMET_TIME, \"\", \"%ld\"\n"
+  "IFIELD      TIMET_TIME, \"\", \"%lld\"\n"
   "IFIELD      EXCEL_TIME, \"\", \"%f\"\n"
 
   "# EPILOGUE:\n"
@@ -309,7 +309,7 @@ static char garmin301[] =
   "#\n"
   "# INDIVIDUAL DATA FIELDS:\n"
   "#\n"
-  "IFIELD      TIMET_TIME,\"\",\"%ld\"\n"
+  "IFIELD      TIMET_TIME,\"\",\"%lld\"\n"
   "IFIELD      LAT_DECIMAL, \"\", \"%f\"\n"
   "IFIELD      LON_DECIMAL, \"\", \"%f\"\n"
   "IFIELD      ALT_FEET, \"\", \"%fF\"\n"
@@ -969,7 +969,7 @@ static char motoactv[] =
   "IFIELD IGNORE,\"\",\"%s\" # repetitions\n"
   "IFIELD TEMPERATURE,\"\",\"%.1f\"\n"
   "IFIELD IGNORE,\"\",\"%s\" # instant torque crank\n"
-  "IFIELD TIMET_TIME_MS,\"\",\"%ld\"\n"
+  "IFIELD TIMET_TIME_MS,\"\",\"%lld\"\n"
   "IFIELD ALT_METERS,\"\",\"%.1f\"\n"
   "IFIELD POWER,\"\",\"%.0f\"\n"
   "IFIELD IGNORE,\"\",\"%s\" # strides\n"
@@ -1294,7 +1294,7 @@ static char tabsep[] =
   "IFIELD      ALT_FEET, \"\", \"%fF\"\n"
   "IFIELD      ALT_METERS, \"\", \"%fM\"\n"
   "IFIELD      EXCEL_TIME, \"\", \"%f\"\n"
-  "IFIELD      TIMET_TIME, \"\", \"%ld\"\n"
+  "IFIELD      TIMET_TIME, \"\", \"%lld\"\n"
   "IFIELD  GEOCACHE_DIFF,\"\",\"%3.1f\"\n"
   "IFIELD  GEOCACHE_TERR,\"\",\"%3.1f\"\n"
   "IFIELD  GEOCACHE_CONTAINER,\"\",\"%s\"\n"
index 528ac85ed2bd75b7694698c352a03f5e27e58bf2..b90556f7dd166f90e31ab57714c9c219a4b89de1 100644 (file)
@@ -44,7 +44,7 @@ IFIELD        LAT_DIRDECIMAL, "", "%c/%f"
 IFIELD LON_DIRDECIMAL, "", "%c/%f"
 IFIELD LAT_INT32DEG, "", "%ld"
 IFIELD LON_INT32DEG, "", "%ld"
-IFIELD TIMET_TIME, "", "%ld"
+IFIELD TIMET_TIME, "", "%lld"
 IFIELD EXCEL_TIME, "", "%f"
 
 # EPILOGUE:
index 6c7a7395600783b800f7a802d648a18632e1db7e..2922986dab52a9da277b6de9d74deea299b3c750 100644 (file)
@@ -22,7 +22,7 @@ PROLOGUE      Timestamp,Latitude, Longitude, Altitude(ft), heart rate
 #
 # INDIVIDUAL DATA FIELDS:
 #
-IFIELD TIMET_TIME,"","%ld"
+IFIELD TIMET_TIME,"","%lld"
 IFIELD LAT_DECIMAL, "", "%f"
 IFIELD LON_DECIMAL, "", "%f"
 IFIELD ALT_FEET, "", "%fF"
index 8cbe2599c6e037479005b2c5a381db3b49641e94..9029f41cb09b9fcc70c0b3350a12c5f2f1ed8f76 100644 (file)
@@ -28,7 +28,7 @@ IFIELD LAT_DECIMAL,"","%.6f"
 IFIELD IGNORE,"","%s" # repetitions
 IFIELD TEMPERATURE,"","%.1f"
 IFIELD IGNORE,"","%s" # instant torque crank
-IFIELD TIMET_TIME_MS,"","%ld"
+IFIELD TIMET_TIME_MS,"","%lld"
 IFIELD ALT_METERS,"","%.1f"
 IFIELD POWER,"","%.0f"
 IFIELD IGNORE,"","%s" # strides
index 1dd43bbdc9c38b21746380467fe5ba4161593f6d..7857d800386d391182587009c2b00e2b946c032a 100644 (file)
@@ -44,7 +44,7 @@ IFIELD        LON_DIR, "", "%c"
 IFIELD ALT_FEET, "", "%fF"
 IFIELD ALT_METERS, "", "%fM"
 IFIELD EXCEL_TIME, "", "%f"
-IFIELD TIMET_TIME, "", "%ld"
+IFIELD TIMET_TIME, "", "%lld"
 IFIELD  GEOCACHE_DIFF,"","%3.1f"
 IFIELD  GEOCACHE_TERR,"","%3.1f"
 IFIELD  GEOCACHE_CONTAINER,"","%s"
diff --git a/xcsv.cc b/xcsv.cc
index d61d9f73a08f4287a3d36a4551a300dd986e9ef7..a9750bc4ce626e5ee3e421114581f8c9b8ff58dd 100644 (file)
--- a/xcsv.cc
+++ b/xcsv.cc
@@ -611,10 +611,15 @@ XcsvFormat::xcsv_parse_val(const QString& value, Waypoint* wpt, const XcsvStyle:
     /* Time as Excel Time  */
     wpt->SetCreationTime(excel_to_timet(atof(s)));
     break;
-  case XT_TIMET_TIME:
+  case XT_TIMET_TIME: {
     /* Time as time_t */
-    wpt->SetCreationTime((time_t) atol(s));
-    break;
+    bool ok;
+    wpt->SetCreationTime(value.toLongLong(&ok));
+    if (!ok) {
+      warning("parse of string '%s' on line number %d as TIMET_TIME failed.\n", s, line_no);
+    }
+  }
+  break;
   case XT_TIMET_TIME_MS: {
     /* Time as time_t in milliseconds */
     bool ok;
@@ -1342,20 +1347,13 @@ XcsvFormat::xcsv_waypt_pr(const Waypoint* wpt)
       buff = QString::asprintf(fmp.printfc.constData(), timet_to_excel(wpt->GetCreationTime().toTime_t()));
       break;
     case XT_TIMET_TIME:
-      /* time as a time_t variable */
-    {
-      time_t tt = wpt->GetCreationTime().toTime_t();
-      buff = QString::asprintf(fmp.printfc.constData(), tt);
-    }
-    break;
-
-    case XT_TIMET_TIME_MS: {
+      /* time as a time_t variable in seconds */
+      buff = QString::asprintf(fmp.printfc.constData(), wpt->GetCreationTime().toSecsSinceEpoch());
+      break;
+    case XT_TIMET_TIME_MS:
       /* time as a time_t variable in milliseconds */
-      buff = writetime("%s", wpt->GetCreationTime().toTime_t(), false);
-      buff += QString::asprintf("%03d", wpt->GetCreationTime().time().msec());
-
-    }
-    break;
+      buff = QString::asprintf(fmp.printfc.constData(), wpt->GetCreationTime().toMSecsSinceEpoch());
+      break;
     case XT_YYYYMMDD_TIME:
       buff = QString::asprintf(fmp.printfc.constData(), time_to_yyyymmdd(wpt->GetCreationTime()));
       break;
index 1fd535470eeee0db630319934b20054fb5eb7e93..1e89332ab3313848ab9683d643839923dd7f2f49 100644 (file)
@@ -807,24 +807,24 @@ longitude)
       <section id="style_def_timettime">
          <title>TIMET_TIME</title>
          <para>TIMET_TIME is the waypoint's creation time, if any.  This is actually
-   the integer seconds since 1/1/1970 (let's not start the holy war) and
-   is handled internally as a LONG INTEGER and requires a LONG INTEGER
+   the integer seconds since 1970-01-01T00:00:00 UTC. It
+   is handled internally as a 64 bit integer and requires a LONG LONG INTEGER
    printf conversion.
 </para>
          <para>example:
 </para>
-         <screen format="linespecific">IFIELD TIMET_TIME,&quot;&quot;,&quot;%ld&quot;
+         <screen format="linespecific">IFIELD TIMET_TIME,&quot;&quot;,&quot;%lld&quot;
 </screen>
       </section>
       <section id="style_def_timettimems">
          <title>TIMET_TIME_MS</title>
          <para>TIMET_TIME_MS is the same as TIMET_TIME, but expressed in milliseconds.
-   It too is handled internally as a LONG INTEGER and requires a LONG INTEGER
+   It too is handled internally as a 64 bit integer and requires a LONG LONG INTEGER
    printf conversion.
 </para>
          <para>example:
 </para>
-         <screen format="linespecific">IFIELD TIMET_TIME_MS,&quot;&quot;,&quot;%ld&quot;
+         <screen format="linespecific">IFIELD TIMET_TIME_MS,&quot;&quot;,&quot;%lld&quot;
 </screen>
       </section>
       <section id="style_def_yyyymmdd">